module Proyecto1	(mini,
					sumarList,
					encabs,
					encuentra,
					primIgualesA
					)
where

mini :: (Bounded a, Ord a) => [a] -> a
mini [] = maxBound
mini (x:xs) |x < mini xs = x
				|otherwise = mini xs

minif :: (Bounded a, Ord a) => [a] -> a
minif xs = foldr min maxBound xs

sumarList :: Num a => a -> [a] -> [a]
sumarList _ [] = []
sumarList n (x:xs) = (n+x) : sumarList n xs 

sumarListm :: Num a => a -> [a] -> [a]
sumarListm n xs = map (+n) xs

encabs :: a -> [[a]] -> [[a]]
encabs n [] = []
encabs n (x:xs) = (n:x) : encabs n xs

encabsm :: a -> [[a]] -> [[a]]
encabsm n xs = map (n:) xs
 
encuentra :: Int -> [(Int,String)] -> String
encuentra n [] = ""
encuentra n ((x,y):xs)  |n==x = y
								|otherwise = encuentra n xs

encuentraf :: Int -> [(Int,String)] -> String
encuentraf n xs = foldr f "" xs
						where 
						f :: (Int, String) -> String -> String						
						f (x,y) s 	|n==x = y
										|otherwise = s

primIgualesA :: Eq a => a -> [a] -> [a]
primIgualesA n [] = []
primIgualesA n (x:xs)	|n==x = [x] ++ primIgualesA n xs
								|otherwise = []

primIgualesAf :: Eq a => a -> [a] -> [a]
primIgualesAf n xs = foldr f [] xs
							where
							f c ys 	|c==n = c:ys
										|otherwise = []

primIgualesAt :: Eq a => a -> [a] -> [a]
primIgualesAt n xs = takeWhile (==n) xs

primIguales :: Eq a => [a] -> [a]
primIguales [] = []
primIguales (x:xs) = takeWhile (==x) (x:xs)

subsecs :: Eq a => (a->Bool) -> [a] -> [[a]]
subsecs p [] = []
subsecs p (x:xs)  |p x = (x: takeWhile p xs) : (subsecs p (dropWhile p xs))
						|otherwise = subsecs p xs
							
